﻿using System;
using System.Collections.Generic;

// 定义形状接口
public interface IShape
{
    double CalculateArea();
    bool IsValid();
}

// 长方形类
public class Rectangle : IShape
{
    public double Length { get; }
    public double Width { get; }

    public Rectangle(double length, double width)
    {
        Length = length;
        Width = width;
    }

    public double CalculateArea() => IsValid() ? Length * Width : 0;

    public bool IsValid() => Length > 0 && Width > 0;
}

// 正方形类
public class Square : IShape
{
    public double Side { get; }

    public Square(double side)
    {
        Side = side;
    }

    public double CalculateArea() => IsValid() ? Side * Side : 0;

    public bool IsValid() => Side > 0;
}

// 圆形类
public class Circle : IShape
{
    public double Radius { get; }

    public Circle(double radius)
    {
        Radius = radius;
    }

    public double CalculateArea() => IsValid() ? Math.PI * Radius * Radius : 0;

    public bool IsValid() => Radius > 0;
}

class Program
{
    static void Main()
    {
        var random = new Random();
        var shapes = new List<IShape>();

        // 随机生成10个形状
        for (int i = 0; i < 10; i++)
        {
            int type = random.Next(0, 3);
            switch (type)
            {
                case 0: // 长方形
                    double length = (random.NextDouble() - 0.5) * 10;
                    double width = (random.NextDouble() - 0.5) * 10;
                    shapes.Add(new Rectangle(length, width));
                    break;
                case 1: // 正方形
                    double side = (random.NextDouble() - 0.5) * 10;
                    shapes.Add(new Square(side));
                    break;
                case 2: // 圆形
                    double radius = (random.NextDouble() - 0.5) * 10;
                    shapes.Add(new Circle(radius));
                    break;
            }
        }

        // 计算总面积
        double totalArea = 0;
        foreach (var shape in shapes)
        {
            totalArea += shape.CalculateArea();
        }

        Console.WriteLine($"合法形状的总面积为: {totalArea:F2}");
    }
}